(define (sum term a next b)
    (if (> a b )
        0
        (+  (term a)
            (sum term (next a) next b))
    )
)
(define (integral f a b dx)
    (define (add-dx x)
        (+ x dx)
    )
    (*  (sum f (+ a (/ dx 2.0)) add-dx b)
        dx
    )
)
(define (cube x)
    ( * x x x)
)
(display (integral cube 0 1 0.01))
(newline)
(display (integral cube 0 1 0.001))
(newline)

(define (simpson f a b n)
    (define h
        (/ (- b a) n)
    )
    (define (add2h x)
        (+ x (* 2 h))
    )
    (define (4f x)
        (* 4 (f x))   
    )
    (define (2f x)
        (* 2 (f x))
    )
    (*  (+  
            (f a)
            (f b) 
            (sum 4f 
                (+ a h)
                add2h
                b
            )
            (sum 2f 
                (+ a h h)
                add2h
                b
            )
        )            
        (/ h 3) 
    )
)
(display (simpson cube 0.0 1.0 100))
(newline)
(display (simpson cube 0.0 1.0 1000))
(newline)
(display (simpson cube 0.0 1.0 10000))
(exit)